<template>
  <div class="main">
    <view class="user_info" @click="toUserinfoEdit">
      <text class="user_name">{{userinfo.nick_name}}</text>
      <text class="user_name_desc">查看并编辑个人资料</text>
      <image class="user_avatar" :src="userinfo.avatar"></image>
    </view>

    <view class="user_func">
      <view class="func_setting" @click="toSetting">
        <img class="func_icon" src='http://fanglilai-pic.oss-cn-shenzhen.aliyuncs.com/mw690/20180611/2018061110064592995.jpg'></img>
        <text class="func_desc">设置</text>
      </view>
      <!-- <view class="func_setting">
        <img class="func_icon" src="/static/img/icon_contract.png"></img>
        <text class="func_desc">合同模板</text>
      </view> -->
      <!-- <view class="func_setting" @click="toAbout">
        <img class="func_icon" src='http://fanglilai-pic.oss-cn-shenzhen.aliyuncs.com/mw690/20180619/2018061903575049853.jpg'></img>
        <text class="func_desc">关于我们</text>
      </view> -->
    </view>

  </div>
</template>

<script>
import api from '@/utils/api'
import store from '@/store/store'

export default {
  data () {
    return {
      userinfo: {},
      avatar: 'http://fanglilai-pic.oss-cn-shenzhen.aliyuncs.com/mw690/20180627/2018062711040724129.jpg'
    }
  },
  methods: {
    toSetting () {
      this.$router.push({ path: '/pages/me/setting/main' })
    },
    toAbout () {
      this.$router.push({ path: '/pages/me/about_us/main' })
    },
    toUserinfoEdit () {
      store.commit('setNickName', this.userinfo.nick_name)
      store.commit('setAvatar', this.userinfo.avatar)
      this.$router.push({ path: '/pages/me/userinfo_edit/main' })
    },
    opuserinfoget () {
      const opuserinfoget = api.opuserinfoget()
      opuserinfoget.then(d => {
        if (d.code === 200) {
          this.userinfo = d.data
          this.avatar = d.avatar
        }
      })
      .catch((e) => {
        console.log(e)
      })
    }
  },
  onShow () {
    this.opuserinfoget()
  }
}
</script>

<style>
@import './meindex.css';
</style>
